<template>
	<view class="container container333638">
		<view class="flex diygw-col-24">
			<u-tabs class="diygw-col-24" name="title" count="badge" font-size="28" :list="cates.rows" active-color="#2a65fd" inactive-color="#606266" :is-scroll="false" :current="utabs" @change="changeUtabs"></u-tabs>
		</view>
		<u-form-item :borderBottom="false" v-if="globalData.isshow" class="diygw-col-24 title-clz" labelPosition="top" prop="title">
			<u-input @blur="listApi" :data-title_like="title" :focus="titleFocus" placeholder="请输入产品标题" v-model="title"></u-input>
			<text @tap="navigateTo" data-type="listApi" :data-title_like="title" class="diy-icon-search" style="color: #363636; font-size: 32rpx"></text>
		</u-form-item>
		<view v-if="list.total > 0" class="flex flex-wrap diygw-col-24 flex-direction-column">
			<view v-for="(item, index) in list.rows" :key="index" class="flex flex-wrap diygw-col-24 items-stretch flex2-clz" @tap="navigateTo" data-type="page" data-url="/pages/article" :data-id="item.id">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column justify-between flex20-clz">
					<text class="diygw-col-0 text11-clz">
						{{ item.title }}
					</text>
					<text class="diygw-text-line3 diygw-col-0">
						{{ item.remark }}
					</text>
				</view>
				<view class="flex flex-wrap diygw-col-0 items-center flex4-clz">
					<image :src="item.img" class="image1-size diygw-image diygw-col-0" mode="scaleToFill"></image>
				</view>
			</view>
		</view>
		<view v-if="globalData.isshow && list.code == 200 && list.total == 0" class="flex flex-wrap diygw-col-24 flex-direction-column items-center flex-clz">
			<image src="/static/zwjl.png" class="image-size diygw-image diygw-col-0" mode="widthFix"></image>
			<text class="diygw-col-0 text-clz"> 未找到任何数据 </text>
		</view>
		<view class="flex flex-wrap diygw-col-24 items-end diygw-bottom flex6-clz">
			<view class="flex flex-wrap diygw-col-6 flex-direction-column items-center flex8-clz">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column items-center">
					<image src="/static/sy3.png" class="image2-size diygw-image diygw-col-0" mode="widthFix"></image>
				</view>
				<text class="diygw-text-line1 diygw-col-0"> 首页 </text>
			</view>
			<view class="flex flex-wrap diygw-col-6 flex-direction-column items-center flex10-clz" @tap="navigateTo" data-type="page" data-url="/pages/products">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column items-center">
					<image src="/static/cp1.png" class="image3-size diygw-image diygw-col-0" mode="widthFix"></image>
				</view>
				<text class="diygw-text-line1 diygw-col-0"> 产品 </text>
			</view>
			<view class="flex flex-wrap diygw-col-6 flex-direction-column items-center flex13-clz" @tap="navigateTo" data-type="page" data-url="/pages/msg/edit">
				<image src="/static/fb.png" class="image6-size diygw-image diygw-col-0 image6-clz" mode="widthFix"></image>
				<text class="diygw-text-line1 diygw-col-0 text6-clz"> 在线预约 </text>
			</view>
			<view class="flex flex-wrap diygw-col-6 flex-direction-column items-center flex14-clz">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column items-center">
					<text class="diygw-text-line1 diygw-col-0 animate__animated animate__heartBeat animate__infinite text7-clz"> </text>
					<image src="/static/xw.png" class="image4-size diygw-image diygw-col-0" mode="widthFix"></image>
				</view>
				<text class="diygw-text-line1 diygw-col-0 text8-clz"> 新闻资讯 </text>
			</view>
			<view class="flex flex-wrap diygw-col-6 flex-direction-column items-center flex15-clz" @tap="navigateTo" data-type="page" data-url="/pages/user" data-redirect="1">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column items-center">
					<image src="/static/wd.png" class="image5-size diygw-image diygw-col-0" mode="widthFix"></image>
				</view>
				<text class="diygw-text-line1 diygw-col-0"> 我的 </text>
			</view>
		</view>
		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: { isshow: false },
				listNum: 1,
				list: {
					rows: [
						{
							id: 0,
							title: '',
							remark: '',
							img: '',
							content: null,
							cateId: 0,
							userId: 0,
							createTime: '',
							updateTime: '',
							deleteTime: null
						}
					],
					total: 0,
					code: 0,
					msg: ''
				},
				catesNum: 1,
				cates: {
					rows: [
						{
							id: 0,
							title: '',
							remark: '',
							img: '',
							userId: 0,
							createTime: '',
							updateTime: '',
							deleteTime: null
						}
					],
					total: 0,
					code: 0,
					msg: ''
				},
				utabs: 0,
				titleFocus: false,
				title: ''
			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				await this.listApi();
				await this.catesApi();
			},
			// 列表数据 API请求方法
			async listApi(param) {
				let thiz = this;
				param = param || {};

				//如果请求要重置页面，请配置点击附加参数refresh=1  增加判断如输入框回调param不是对象
				if (param.refresh || typeof param != 'object') {
					this.listNum = 1;
				}

				//请求地址及请求数据，可以在加载前执行上面增加自己的代码逻辑
				let http_url = '/cms/api.article/list';
				let http_data = {
					pageNum: this.listNum,
					pageSize: 10,
					title_like: param.title_like || this.title
				};
				let http_header = {};

				if (this.cates.rows.length > 0 && this.utabs > 0) {
					let row = this.cates.rows[this.utabs];
					if (row.id) {
						http_data.cateId = row.id;
					}
				}

				let list = await this.$http.post(http_url, http_data, http_header, 'json');

				let datarows = list.rows;
				if (http_data.pageNum == 1) {
					this.list = list;
				} else if (datarows) {
					let rows = this.list.rows.concat(datarows);
					list.rows = rows;
					this.list = list;
				}
				if (datarows && datarows.length > 0) {
					this.listNum = this.listNum + 1;
				}
				this.globalData.isshow = true;
			},
			// 分类数据 API请求方法
			async catesApi(param) {
				let thiz = this;
				param = param || {};

				//请求地址及请求数据，可以在加载前执行上面增加自己的代码逻辑
				let http_url = '/cms/api.cate/list';
				let http_data = {
					pageNum: this.catesNum,
					pageSize: 10,
					pageSize: param.pageSize || '20'
				};
				let http_header = {};

				let cates = await this.$http.post(http_url, http_data, http_header, 'json');

				cates.rows.unshift({ id: '', title: '全部' });

				this.cates = cates;
			},

			// 修改数据 自定义方法
			async editFunction(param) {
				let thiz = this;
				let index = param && (param.index || param.index == 0) ? param.index : thiz.index || '';
				this.form = JSON.parse(JSON.stringify(this.list.rows[param.index]));
				this.navigateTo({
					type: 'openmodal',
					id: 'modal'
				});
			},
			changeUtabs(evt) {
				this.utabs = evt;
				this.navigateTo({ title_like: this.title, refresh: 1, type: 'listApi' });
			}
		},
		onPullDownRefresh() {
			// 列表数据 API请求方法
			this.listNum = 1;
			this.listApi();

			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			// 列表数据 API请求方法
			this.listApi();
		}
	};
</script>

<style lang="scss" scoped>
	.title-clz {
		background-color: #ffffff;
		margin-left: 16rpx;
		border-bottom-left-radius: 12rpx;
		overflow: hidden;
		width: calc(100% - 16rpx - 16rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 16rpx;
		border-top-right-radius: 12rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 16rpx;
		margin-right: 16rpx;
	}
	.flex2-clz {
		padding-top: 20rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		border-top-right-radius: 12rpx;
		margin-right: 20rpx;
		background-color: #ffffff;
		margin-left: 20rpx;
		box-shadow: 0rpx 0rpx 12rpx 2px rgba(219, 219, 219, 0.31);
		overflow: hidden;
		width: calc(100% - 20rpx - 20rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 20rpx;
	}
	.flex20-clz {
		padding-top: 10rpx;
		flex: 1;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}
	.text11-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}
	.flex4-clz {
		background-color: rgba(236, 236, 236, 0.37);
		border-bottom-left-radius: 12rpx;
		overflow: hidden;
		border-top-left-radius: 12rpx;
		border-top-right-radius: 12rpx;
		border-bottom-right-radius: 12rpx;
	}
	.image1-size {
		height: 120rpx !important;
		width: 160rpx !important;
	}
	.flex-clz {
		padding-top: 20rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		padding-right: 20rpx;
	}
	.image-size {
		height: 400rpx !important;
		width: 400rpx !important;
	}
	.text-clz {
		color: #969696;
		font-size: 28rpx !important;
	}
	.flex6-clz {
		border-top: 2rpx solid #e4e4e4;
		padding-top: 16rpx;
		border-bottom-left-radius: 0rpx;
		bottom: 0rpx;
		padding-left: 16rpx;
		padding-bottom: 16rpx;
		border-top-right-radius: 24rpx;
		background-color: #ffffff;
		box-shadow: 0rpx 4rpx 12rpx rgba(31, 31, 31, 0.16);
		overflow: visible;
		left: 0rpx;
		border-top-left-radius: 24rpx;
		border-bottom-right-radius: 0rpx;
		padding-right: 16rpx;
	}
	.flex8-clz {
		flex: 1;
	}
	.image2-size {
		height: 48rpx !important;
		width: 48rpx !important;
	}
	.flex10-clz {
		flex: 1;
	}
	.image3-size {
		height: 48rpx !important;
		width: 48rpx !important;
	}
	.flex13-clz {
		margin-left: 0rpx;
		flex: 1;
		width: calc(25% - 0rpx - 0rpx) !important;
		margin-top: -100rpx;
		margin-bottom: 0rpx;
		margin-right: 0rpx;
	}
	.image6-clz {
		border-bottom-left-radius: 120rpx;
		box-shadow: 0rpx 2rpx 10rpx 1px rgba(31, 31, 31, 0.16);
		overflow: hidden;
		border-top-left-radius: 120rpx;
		border-top-right-radius: 120rpx;
		border-bottom-right-radius: 120rpx;
	}
	.image6-size {
		height: 80rpx !important;
		width: 80rpx !important;
	}
	.text6-clz {
		margin-left: 0rpx;
		margin-top: 16rpx;
		margin-bottom: 0rpx;
		margin-right: 0rpx;
	}
	.flex14-clz {
		flex: 1;
	}
	.text7-clz {
		border: 2rpx solid #eee;
		border-bottom-left-radius: 40rpx;
		-webkit-animation-duration: 5000ms;
		color: #ffffff;
		animation-delay: 1000ms;
		-webkit-animation-delay: 1000ms;
		border-top-right-radius: 40rpx;
		right: -8rpx;
		background-color: rgba(255, 17, 17, 0.91);
		animation-duration: 5000ms;
		flex-shrink: 0;
		overflow: hidden;
		top: -8rpx;
		width: 16rpx !important;
		border-top-left-radius: 40rpx;
		border-bottom-right-radius: 40rpx;
		position: absolute;
		height: 16rpx !important;
	}
	.image4-size {
		height: 48rpx !important;
		width: 48rpx !important;
	}
	.text8-clz {
		color: #031aeb;
	}
	.flex15-clz {
		flex: 1;
	}
	.image5-size {
		height: 48rpx !important;
		width: 48rpx !important;
	}
	.container333638 {
		padding-bottom: 160rpx;

		background-image: url(/static/loginbg.png);
	}
</style>
